package com.likui.myqq.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;

import com.likui.myqq.R;
import com.likui.myqq.util.SDManager;
import com.likui.myqq.util.SpUtil;

public class WelcomeActivity extends Activity {

    private static final String TAG = WelcomeActivity.class.getName();
    private Context mContext;
    private ImageView ivWelcome;
    private SharedPreferences sp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        mContext = this;
        findView();
        init();
    }

    private void init() {
        ivWelcome.postDelayed(new Runnable() {

            @Override
            public void run() {
                sp = SpUtil.getInstance().getSharedPreference(mContext);
                boolean first = SpUtil.isFirst(sp);
                if (first) {
                    SDManager manager = new SDManager(mContext);
                    manager.moveUserIcon();

                    SpUtil.getInstance().setBooleanPreferences(sp, "isFirst", false);
                    Intent intent = new Intent(WelcomeActivity.this,
                            LoginActivity.class);
                    startActivity(intent);
                    finish();
                } else {
                    Intent intent = new Intent(WelcomeActivity.this,
                            LoginActivity.class);
                    startActivity(intent);
                    finish();
                }
            }
        }, 2000);
    }

    private void findView() {
        ivWelcome = (ImageView) findViewById(R.id.ivWelcome);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.welcome, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
